package net.lzzy.practicesapi1.entities;

import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *  本项目解决实体类间互相引用导致的json序列化无限递归问题，使用视图模型类方式，不再使用注解
 * @author locker
 */
@Entity
@Getter
@Setter
public class Course extends BaseEntity{
    private String name;
    private String description;
    private String cover;
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    @Temporal(TemporalType.TIMESTAMP)
    private Date updateTime;
    private boolean open;

    @ManyToOne
    private User teacher;
    @ManyToMany
    private List<User> students = new ArrayList<>();
    @OneToMany(mappedBy = "course")
    private List<Chapter> chapters = new ArrayList<>();
    @OneToMany(mappedBy = "course")
    private List<Applicant> applicants = new ArrayList<>();

    public Course(){
        createTime = new Date();
        updateTime = createTime;
    }
}
